package com.example.myprojectoffeixue;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

//场景fragment的场景列表适配器
public class Cjadapter extends BaseAdapter {
    private Context context;
    private List<CJutil> list1;
    private ImageView mImageView;
    private int flag;
    private TextView h_tv;

    public Cjadapter(Context context, ArrayList<CJutil> list1, int flag) {
        this.context = context;
        this.list1 = list1;
        this.flag = flag;
        this.h_tv=h_tv;
    }

    @Override
    public int getCount() {

        return list1.size();
    }


    @Override
    public Object getItem(int position) {

        return list1.get(position);

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.wangguan_item, null);
            viewHolder = new ViewHolder();
            viewHolder.tv = (TextView) convertView.findViewById(R.id.tv_wangguanitem);
            viewHolder.iv = (ImageView) convertView.findViewById(R.id.iv_wangguanitem);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        if (list1.size() != 0) {

            if (flag == 1) {

                viewHolder.tv.setText(list1.get(position).sceneName);
                viewHolder.iv.setImageResource(R.drawable.icon_shoudong_kaiqi);

            } else if (flag == 2) {

                viewHolder.tv.setText(list1.get(position).sceneName);
                if ("1".equals(list1.get(position).sceneStatus)) {
                    viewHolder.iv.setImageResource(R.drawable.dingshiguan);
                } else if("2".equals(list1.get(position).sceneStatus)) {
                    viewHolder.iv.setImageResource(R.drawable.icon_zidongg_kaiqi);


                }
            } else if (flag == 3) {

                viewHolder.tv.setText(list1.get(position).sceneName);
                if ("2".equals(list1.get(position).sceneStatus)) {
                    viewHolder.iv.setImageResource(R.drawable.iconliandongkaiqi);
                } else if("1".equals(list1.get(position).sceneStatus)) {
                    viewHolder.iv.setImageResource(R.drawable.liandonguanbi);

                }


            }
        }


        return convertView;


    }


    class ViewHolder {
        TextView tv;
        ImageView iv;

    }


}